var class_num=location.search;
class_num=class_num.split('?')[1];
$('header .title').append(class_num);
$('.card-courseware a').attr('href','file_courseware.html?'+class_num);
if (islogin()) {

    $.post({
        url:'../../requests/teacher/select_courseware.php',
        data:{'class':class_num},
        success:function (data) {
           for (var i=0;i<data.length;i++){
               if (data[i].section != 0) {
                   var dom1="<li class='item-content'><div class='item-inner'>" +"<div class='item-title'><span>第</span><span>"+data[i].section+"</span><span>章</span></div>";
               }
               else dom1="";
               if (data[i].subsection != 0) {
                   var dom2="<div class='item-after'><span>第</span><span>"+data[i].subsection+"</span><span>节</span></div>"+"</div></li>";
               }
               else dom2="";
               var dom="<div class='list-block'><ul>" +

                                dom1+dom2+

                            "<li class='item-content'><div class='item-inner'>" +
                                "<div class='item-title'>"+data[i].name+"</div>"+
                            "</div></li>"+
                            "<li class='item-content'>" +
                                "<div class='item-inner'>" +
                                    "<div class='item-title'><span><button class='button btn_del' id='"+data[i].Id+"'>删除</button></span></div>"+
                                    "<div class='item-after'><a href='../../"+data[i].attach+"'><span>下载</span><span class='icon icon-download'></span></a></div>"+
                                "</div>"+
                            "</li>"+
                        "</ul></div>";
               $('.content').append(dom);
           }
        }
    });
    $('#add-courseware').click(function () {
        window.location.href='add_courseware.html?'+class_num;
    });

    $('.content').on('click','.btn_del',function () {
        var id=$(this).attr('id');
        $$.confirm("确认删除？",function () {
            $.post({
                url:'../../requests/teacher/del_courseware.php',
                data:{'id':id},
                success:function (data) {
                    if (data == '1') {
                        $$.alert('删除成功！',function () {
                            location.reload(true);
                        });
                    }
                    if (data == '0') {
                        $$.alert('删除失败！');
                    }
                }
            });
        });
    });

}
else window.location.href='../../index.html';